package com.example.commons.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DateTimeUtil {


    /**
     * 用于设定现在时间提前多少小时的
     * @param startDay:开始时间 ，yyyy-MM-dd HH:mm:ss
     * @param  hours :增加的时间 （提前，用正整数， 推后时间用负整数）
     */
    public static String  getPostponeTimesOradvanceTimes(Date startDate, int hours){
        Map<Object,Object> ret_map = new HashMap<Object,Object>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String startTime = sdf.format(startDate);
       // System.out.println("现在时间："+startTime);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startDate);
        calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - hours);
        String endTime = sdf.format(calendar.getTime());
        return endTime;
    }
    //判断是否能交卷
    public static boolean dateBefore1(Date date,Integer num) {
                Long time1=date.getTime()+(num*60*1000);
                Long time2=new Date().getTime();
                if(time2>time1){ // 当前时间大于考试时间为true
                    return true;
                }else {
                    return false;
                }

    }

    //判断是否能交卷
    public static boolean dateBefore(Date date,Integer num) {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        Calendar now = Calendar.getInstance();

//
//        System.out.println(sdf.format(now.getTime()));
//        System.out.println(sdf.format(calendar.getTimeInMillis()));
//        System.out.println(calendar.before(now));
        return calendar.before(now);

    }

    public static void main(String[] args) {
        Long time1 =new Date().getTime()+(60*1000);

        Long time2 =new Date().getTime()+(60*1000);

        System.out.println("time1="+time1);
        System.out.println("time2="+time2);
        System.out.println("计算："+(time1-time2));
    }



}
